package com.my.hzb.user.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.my.hzb.entiy.Menu;
import com.my.hzb.entiy.MenuExample;
import com.my.hzb.entiy.MenuExample.Criteria;
import com.my.hzb.mapper.MenuMapper;

public class MenuServiceImpl implements MenuService {

	@Autowired
	private MenuMapper menuMapper;
	
	@Override
	public void add(Menu menu) {
		menu.setCreateTime(new Date());
		menu.setUpdateTime(new Date());
		menuMapper.insert(menu);
	}

	@Override
	public void update(Menu menu) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void delete(Menu menu) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Menu getOne(Integer id) {
		return menuMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<Menu> find(Menu menu) {
		MenuExample menuExample = new MenuExample();
		Criteria criteria = menuExample.createCriteria();
		if(null!=menu.getMenuName()){
			criteria.andMenuNameEqualTo(menu.getMenuName());
		}else if(null!=menu.getMenuParent()){
			criteria.andMenuParentEqualTo(menu.getMenuParent());
		}
		return menuMapper.selectByExample(menuExample);
	}

}
